Skip to content

Conversation

usbalbin
Copy link
Member

@usbalbin usbalbin commented Apr 19, 2023

Hi :)

I have a use case where I need to update the frequency of several pwm outputs very often, therefore I need access to directly setting the period and/or prescaler registers. This PR does that plus some extra methods like start/pause, and access to setting the prescaler.

src/timer/pwm.rs Outdated
self.tim.arr.write(|w| w.$arr().bits(period as u16));
$(
self.tim.arr.modify(|_, w| w.$arr_h().bits((arr >> 16) as u16));
self.tim.arr.modify(|_, w| w.$arr_h().bits((period >> 16) as u16));
Copy link
Member Author

@usbalbin usbalbin Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pwm! {
    TIM1: (tim1, arr),
    TIM3: (tim3, arr_l, arr_h), // should this really have a `arr_h`?
    TIM14: (tim14, arr),
    TIM16: (tim16, arr),
    TIM17: (tim17, arr),
}

I must say that I am a bit confused about the 16/32bit for TIM3. From what I understand from the reference manual for g0x0 TIM3 is just 16-bit. reference manual for g0x1 says pretty much the same thing except it adds a TIM2 which is 32-bit.

Looking at the pac, TIM3 does have an arr_h(inherited from tim2?), same thing when looking in the reference manual...

Also is it really safe to write to arr in two steps without the pwm signal going crazy in between the stores?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me if I am wrong but from what I can gather, TIM3 is 16bits but does share the same memory config structure as TIM2(which is 32bit)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants